home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / ICMPDUMP.C < prev    next >
C/C++ Source or Header  |  1988-07-28  |  1KB  |  76 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "internet.h"
  5. #include "icmp.h"
  6. #include "trace.h"
  7.  
  8. /* Dump an ICMP header */
  9. void
  10. icmp_dump(bpp,source,dest,check)
  11. struct mbuf **bpp;
  12. int32 source,dest;
  13. int check;        /* If 0, bypass checksum verify */
  14. {
  15.     struct icmp icmp;
  16.     int16 csum;
  17.  
  18.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  19.         return;
  20.     csum = cksum(NULLHEADER,*bpp,len_mbuf(*bpp));
  21.     
  22.     ntohicmp(&icmp,bpp);
  23.     
  24.     if(icmp.type <= 16 && icmptypes[icmp.type] != NULLCHAR)
  25.         printf("ICMP: %s",icmptypes[icmp.type]);
  26.     else
  27.         printf("ICMP: type %u",icmp.type);
  28.  
  29.     switch(icmp.type){
  30.     case DEST_UNREACH:
  31.         if(icmp.code <= 5)
  32.             printf(" %s",unreach[icmp.code]);
  33.         else
  34.             printf(" code %u",icmp.code);
  35.         break;
  36.     case REDIRECT:
  37.         if(icmp.code <= 3)
  38.             printf(" %s",redirect[icmp.code]);
  39.         else
  40.             printf(" code %u",icmp.code);
  41.         break;
  42.     case TIME_EXCEED:
  43.         if(icmp.code <= 1)
  44.             printf(" %s",exceed[icmp.code]);
  45.         else
  46.             printf(" code %u",icmp.code);
  47.         break;
  48.     case PARAM_PROB:
  49.         printf(" pointer = %u",icmp.args.pointer);
  50.         break;
  51.     case ECHO:
  52.     case ECHO_REPLY:
  53.     case INFO_RQST:
  54.     case INFO_REPLY:
  55.     case TIMESTAMP:
  56.     case TIME_REPLY:
  57.         printf(" id %u seq %u",icmp.args.echo.id,icmp.args.echo.seq);
  58.         break;
  59.     }
  60.     if(check && csum != 0){
  61.         printf(" CHECKSUM ERROR (%u)",csum);
  62.     }
  63.     printf("\n");
  64.     /* Dump the offending IP header, if any */
  65.     switch(icmp.type){
  66.     case DEST_UNREACH:
  67.     case TIME_EXCEED:
  68.     case PARAM_PROB:
  69.     case QUENCH:
  70.     case REDIRECT:
  71.         printf("Returned ");
  72.         ip_dump(bpp,0);
  73.     }
  74. }
  75.  
  76.